//
//  MTOpenRedpackHistoryCell.swift
//  MT
//
//  Created by ooops on 2019/12/24.
//  Copyright © 2019 张强. All rights reserved.
//

import UIKit
import MTCategory

class MTOpenRedpackHistoryCell: UITableViewCell {
    
    class func reuseIdentity() -> String {
        return "MTOpenRedpackHistoryCellID"
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
        makeConstraint()
        selectionStyle = .none
    }
    
    private func setupUI() {
        contentView.addSubview(nameLabel)
        contentView.addSubview(dateLabel)
        contentView.addSubview(moneyLabel)
        contentView.addSubview(lineView)
    }
    
    var model: MTQueryResultModel? {
        didSet {
            if model != nil {
                nameLabel.text = model?.nickname ?? (model?.redpacketType == 0 ? "普通红包" : model?.redpacketType == 1 ? "平均红包" : "拼手气红包")
                dateLabel.text = model?.createTime
                if let m = model?.money {
                    moneyLabel.text = "\(m)点券"
                }
            }
        }
    }
    
    private func makeConstraint() {
        nameLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(16.auto())
            //make.top.equalToSuperview().offset(26.auto())
            make.bottom.equalTo(contentView.snp.centerY).offset(-2)
        }
        
        dateLabel.snp.makeConstraints { (make) in
            make.left.equalTo(nameLabel)
            //make.top.equalTo(nameLabel.snp.bottom).offset(6.auto())
            make.top.equalTo(contentView.snp.centerY).offset(2)
        }
        
        moneyLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-16.auto())
        }
        
        lineView.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(0.5)
        }
    }
    
    lazy var nameLabel: UILabel = {
        let l = UILabel()
        l.font = PingFangSCRegularFont(14)
        l.textColor = .black
        l.text = ""
        return l
    }()
    
    
    lazy var dateLabel: UILabel = {
        let l = UILabel()
        l.font = PingFangSCRegularFont(14)
        l.textColor = .black
        l.text = ""
        return l
    }()
    
    lazy var moneyLabel: UILabel = {
        let l = UILabel()
        l.font = PingFangSCRegularFont(14)
        l.textColor = .black
        l.text = ""
        return l
    }()
    
    lazy var lineView: UIView = {
        let v = UIView()
        v.backgroundColor = UIColor.seprateLine.x707070
        return v
    }()
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
